package com.winhxd.b2c.product.controller;

import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.product.condition.ProductCategoryCondition;
import com.winhxd.b2c.common.domain.product.condition.ProductCategorySaveCondition;
import com.winhxd.b2c.common.domain.product.model.ProductCategory;
import com.winhxd.b2c.common.domain.product.vo.ProductCategoryVO;
import com.winhxd.b2c.common.feign.product.ProductCategoryServiceClient;
import com.winhxd.b2c.product.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author luosixiang
 */
@Api(value = "商品分类", tags = "product category")
@RestController
public class ProductCategoryController implements ProductCategoryServiceClient {

    private static final Logger logger = LoggerFactory.getLogger(ProductCategoryController.class);

    @Autowired
    private ProductCategoryService productCategoryService;

    @Override
    @ApiOperation(value = "获取商品分类列表", response = ProductCategoryVO.class, notes = "获取商品分类列表")
    public ResponseResult<List<ProductCategoryVO>> findProductCategory() {
        ResponseResult<List<ProductCategoryVO>> result = new ResponseResult<>();
        result.setData(productCategoryService.findAllCategory());
        return result;
    }

    @Override
    @ApiOperation(value = "保存商品分类", response = ProductCategoryVO.class, notes = "保存商品分类")
    public ResponseResult<List<ProductCategoryVO>> saveProductCategory(@RequestBody ProductCategorySaveCondition condition) {
        ResponseResult<List<ProductCategoryVO>> result = new ResponseResult<>();
        result.setData(productCategoryService.saveProductCategory(condition));
        return result;
    }

    @Override
    @ApiOperation(value = "判断该商品分类是否能删除，如果能删除就删除", response = Boolean.class, notes = "判断该商品分类是否能删除，如果能删除就删除")
    public ResponseResult<Boolean> checkAndDeleteProductCategory(@RequestBody ProductCategoryCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        result.setData(productCategoryService.checkAndDeleteProductCategory(condition));
        return result;
    }

    @Override
    @ApiOperation(value = "通过model查询商品分类", response = ProductCategory.class, notes = "通过model查询商品分类")
    public ResponseResult<List<ProductCategory>> findProductCategoryByModel(@RequestBody ProductCategoryCondition productCategory) {
        ResponseResult<List<ProductCategory>> result = new ResponseResult<>();
        result.setData(productCategoryService.findProductCategoryByModel(productCategory));
        return result;
    }
}
